-- CreationDoor
-- Created by huanghr Dec/16/2016
-- 创世之门格子

-- 初始化
function initCreationDoor(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            local times = tonumber(self.gridData.click_times) + 1;
            self.gridData.click_times = times;

            -- 前两次点击时弹出文字提示
            if times < 10 then
                alert(getLocStr("creation_door_tip1"));
                return;
            end

            -- 第三次点击奖励世界之源
            if times == 10 then
                DungeonActionM.go("take_creation_door_bonus", self.gridData.pos);
                return;
            end

            -- 提示没有任何反应
            alert(getLocStr("creation_door_tip3"));
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);

    -- 呼吸动画
    if self.gridData.need_animation == 1 then
        self.needAnimation = true;
    end
end

